#include<iostream>
#include<thread>
#include<unistd.h>

void threadAdd(const char* name, int a, int b, int* ret)
{
    std::cout << "I am " << name << ". I excute add data..." << std::endl;
    sleep(1);
    *ret = a + b;
}


int main()
{
    int a = 0, b = 0, ret = 0;
    std::cout << "请输入你想相加的两个数：";
    std::cin >> a >> b;

    //1.创建线程：
    //函数指针 + 可变参数：
    std::thread mythread(threadAdd, "thread-1", a, b, &ret);

    //2.等待线程：
    mythread.join();
    
    //3.打印结果：
    std::cout << "计算的结果为" << ret << std::endl;
}